package com.dg11185.nearshop.net.entity;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 商家列表实体类
 * 
 * @author：Daibo
 * @time：2014-5-23 上午10:24:04
 */
public class MerchantItem implements Parcelable {
    /** isnull == false */
    public String merchantId = "";

    public String merchantName = "";

    public String address = "";

    public String areaNum = "";

    /***/
    public String longitude = "";

    public String latitude = "";

    public String telephone = "";

    public String oriPhotoUrl = "";

    public String maxPhotoUrl = "";

    public String midPhotoUrl = "";

    public String minPhotoUrl = "";

    public String preferentialType = "";

    public String preferential = "";

    public String discountMsg = "";

    public String avgPrice = "";

    public String avgRating = "";

    public String workTime = "";

    public String industryId = "";

    public String totalLikes = "";

    public String totalComments = "";

    public String isLike = "";

    public String isFavor = "";

    public String totalFavors = "";

    public String brandId = "";

    public String getPreferentialType(String type) {
        int curType = 0;
        String reString = "";
        if ("".equals(type) || type == null) {
            curType = -1;
        } else {
            curType = Integer.parseInt(type);
        }
        switch (curType) {
        case 0:
            reString = "免费";
            break;

        case 1:
            reString = "赠送";
            break;
        case 2:
            reString = discountMsg + " 折";
            break;
        case 3:
            reString = "特价";
            break;
        case 4:
            reString = "会员价";
            break;
        case 5:
            reString = "满送";
            break;
        default:
            reString = "";
            break;
        }
        return reString;
    }

    public void parseEntity(JSONObject object) {

        merchantId = object.optString("merchantId");
        merchantName = object.optString("merchantName");
        address = object.optString("address");
        areaNum = object.optString("areaNum");

        longitude = object.optString("longitude");
        latitude = object.optString("latitude");
//        if (!"".equals(latitude) && !"".equals(longitude)) {
//            String[] point = ConvertUnit.convertGeopoint(latitude, longitude);
//            latitude = point[0];
//            longitude = point[1];
//        }
        telephone = object.optString("telephone");
        oriPhotoUrl = object.optString("oriPhotoUrl");
        minPhotoUrl = object.optString("minPhotoUrl");
        midPhotoUrl = object.optString("midPhotoUrl");
        maxPhotoUrl = object.optString("maxPhotoUrl");
        preferentialType = object.optString("preferentialType");
        preferential = object.optString("preferential");
        discountMsg = object.optString("discountMsg");
        avgPrice = object.optString("avgPrice");
        avgRating = object.optString("avgRating");
        workTime = object.optString("workTime");
        industryId = object.optString("industryId");
        totalLikes = object.optString("totalLikes");
        totalComments = object.optString("totalComments");
        totalFavors = object.optString("totalFavors");
        isLike = object.optString("isLike");
        isFavor = object.optString("isFavor");
        brandId = object.optString("brandId");

    }

    public MerchantItem() {

    }

    public MerchantItem(Parcel in) {
        String[] data = new String[24];
        in.readStringArray(data);
        this.merchantId = data[0];
        this.merchantName = data[1];
        this.address = data[2];
        this.areaNum = data[3];
        this.longitude = data[4];
        this.latitude = data[5];
        this.telephone = data[6];
        this.oriPhotoUrl = data[7];
        this.maxPhotoUrl = data[8];
        this.midPhotoUrl = data[9];
        this.minPhotoUrl = data[10];
        this.preferentialType = data[11];
        this.preferential = data[12];
        this.discountMsg = data[13];
        this.avgPrice = data[14];
        this.avgRating = data[15];
        this.workTime = data[16];
        this.industryId = data[17];
        this.totalLikes = data[18];
        this.totalComments = data[19];
        this.isLike = data[20];
        this.isFavor = data[21];
        this.totalFavors = data[22];
        this.brandId = data[23];
    }

    public static final Parcelable.Creator<MerchantItem> CREATOR = new Creator<MerchantItem>() {

        @Override
        public MerchantItem createFromParcel(Parcel source) {
            return new MerchantItem(source);
        }

        @Override
        public MerchantItem[] newArray(int size) {
            return new MerchantItem[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeStringArray(new String[] { this.merchantId, this.merchantName, this.address, this.areaNum,
                this.longitude, this.latitude, this.telephone, this.oriPhotoUrl, this.maxPhotoUrl, this.midPhotoUrl,
                this.minPhotoUrl, this.preferentialType, this.preferential, this.discountMsg, this.avgPrice,
                this.avgRating, this.workTime, this.industryId, this.totalLikes, this.totalComments, this.isLike,
                this.isFavor, this.totalFavors, this.brandId,

        });
    }
}
